package com.aic.aicdetactor;

import java.util.List;

import com.aicmonitor.aicdetactorsimple.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

@SuppressWarnings("rawtypes")
public class CustomListAdapter extends android.widget.ArrayAdapter {
	private Context mContext;
	private int id;
	private List<String> items;

	@SuppressWarnings("unchecked")
	public CustomListAdapter(Context context, int textViewResourceId, List<String> list) {
		super(context, textViewResourceId, list);
		mContext = context;
		id = textViewResourceId;
		items = list;
	}

	@Override
	public View getView(int position, View v, ViewGroup parent) {
		View mView = v;
		if (mView == null) {
			LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mView = vi.inflate(id, null);
		}

		TextView text = (TextView) mView.findViewById(R.id.tv_log);

		if (items.get(position) != null) {
			if (items.get(position).startsWith("错误")) {
				text.setTextColor(Color.RED);
			} else {
				text.setTextColor(Color.BLACK);
			}
			text.setText(items.get(position));
		}

		return mView;
	}
}
